﻿module Garbage

////// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//            //// ++++++++++++++++++++++++++++++++++++ChebyshevMethodMethods++++++++++++++++++++++++++++++++++++
//            //// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//            /// <summary>
//            /// Solve SLAE using Chebyshev method with chebyshev parametre
//            /// <param name="accur"> accurcy - simply iteration method parameter</param>
//            /// <exception cref="SLAEInitialMatrixCantBeSolvedException"> B Matrix rate less then 1.0</exception>
//            /// </summary>
//            member x.SolveUsingChebyshevMethod (accur:double) (eigenValues:double[]) = 
//                let watch = new Stopwatch()
//                watch.Start()
//                x.CalculateInitialBMatrixAndBVectorWithChebyshevMethod ()
//
//                let vec,iters = x.ChebyshevIteration accur eigenValues
//
//                watch.Stop()
//                let consumedtime = x.m_consumedTime.Add(watch.Elapsed)
//                x.m_consumedTime <- new TimeSpan()
//                x.FormResult vec iters accur consumedtime
//
//            member private x.CalculateInitialBMatrixAndBVectorWithChebyshevMethod() = 
//                let (A:SquareMatrix,h:Vector) = (x.InitialMatrix.Clone(),x.InitialVector.Clone())
//                let distributionList = SLAE.GetRowColumnDistributionList A SLAE.GetAvailableNonZeroElementIndex
//
//                SLAE.SortRowsUsingDistributionList (A,h) distributionList
//
//                let MMatrix = SquareMatrix.GetMatrixAsDiagonal A
//                if(SLAE.CheckMatrixZeroDiagonal MMatrix) then 
//                    raise <| SLAEInitialMatrixCantBeSolvedException
//                let MInvert = SquareMatrix.GetMatrixWithInversedDiagonal MMatrix
//               
//                x.m_BMatrix <-(MInvert * A)
//                x.m_BVector <-(MInvert*h.AsMatrixColumn()).ToVector()
//
//
//
//            member private x.GetTauK tau0 ro0 n k = 
//                let Tk = Math.Cos( ((2.*(float k) - 1.)*Math.PI)/(2.*(float n)))
//                (tau0)/(1.+ro0*Tk)
//
//            member private x.ChebyshevIteration (accur:double) (eigenValues:double[]) = 
//                let lambdaMax = eigenValues.[0]
//                let lambdaMin = eigenValues.[1]
//
//                let csi = lambdaMin/lambdaMax
//                let ro0 = (1.-csi)/(1.+csi)
//                let tau0 = 2./(lambdaMin+lambdaMax)
//                let n0 = Math.Log(2./accur)/(2.*Math.Sqrt(csi))
//                let startB = x.ProducedBMatrix
//                let startH = x.ProducedBVector
//                let E = MatrixGenerators<SquareMatrix>.IdentityMatrix x.ProducedBMatrix.Dimention
//
//                let rec iter (prev:Vector) (iters:int) = 
//                    let TauNext =  x.GetTauK tau0 ro0 n0 (iters+1) 
//                    prev.Print()
//                    printfn "TAU: %f" TauNext
//                    let next = TauNext*startH + ((E - TauNext*startB)*prev.AsMatrixColumn()).ToVector()
//                    if (Rates.FrobeniusRate (prev - next) < accur) || iters = int n0 then
//                        (next,iters)
//                    else
//                        iter next (iters+1)
//
//                if x.m_initialVectorIsZero then
//                    iter (new Vector([| for i in 0..(x.m_BVector.Length - 1) -> 0. |])) 1
//                else
//                    iter x.m_BVector 1
//                    
//
//            member private x.GetTauParamAsMaxFrobeniusRate() = 
//                let rate = Rates.FrobeniusRate x.InitialMatrix
//                rate * 2.
//
//
//            static member private GetAvailableNonZeroElementIndex (curVec:Vector) 
//                        (availableCols:System.Collections.Generic.List<int>) 
//                        (passedCols:System.Collections.Generic.List<int*int>) = 
//                let rec findNonZero (curVec:Vector) (availableCols:System.Collections.Generic.List<int>) count = 
//                    let index = availableCols.[count]
//                    if (passedCols.FindIndex (fun (row,col) -> col = index)) = -1  then
//                        if curVec.[index] <> 0. || count = ( availableCols.Count - 1) then
//                            index
//                        else
//                            findNonZero curVec availableCols (count+1)
//                    else
//                        findNonZero curVec availableCols (count+1) 
//
//                findNonZero curVec availableCols 0
//

//
